home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu248.dms / pu248.adf / Intuition / Miscellaneous / Example4.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  188 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: Miscellaneous               Tulevagen 22       */
  8. /* File:    Example4.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example shows how to handle double mouse button events. */
  21.  
  22.  
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30.  
  31.  
  32. /* Declare a pointer to a Window structure: */ 
  33. struct Window *my_window;
  34.  
  35. /* Declare and initialize your NewWindow structure: */
  36. struct NewWindow my_new_window=
  37. {
  38.   50,            /* LeftEdge    x position of the window. */
  39.   25,            /* TopEdge     y positio of the window. */
  40.   400,           /* Width       400 pixels wide. */
  41.   100,           /* Height      100 lines high. */
  42.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  43.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  44.   CLOSEWINDOW|   /* IDCMPFlags  We will recieve a message when the user:  */
  45.                  /*             selects the Close window gad, or when the */
  46.   MOUSEBUTTONS,  /*             user presses/releases the mouse buttons.  */
  47.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  48.   WINDOWCLOSE|   /*             Close Gadget. */
  49.   WINDOWDRAG|    /*             Drag gadget. */
  50.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  51.   WINDOWSIZING|  /*             Sizing Gadget. */
  52.   ACTIVATE,      /*             The window should be Active when opened. */
  53.   NULL,          /* FirstGadget No gadgets connected to this window. */
  54.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  55.   "DOUBLE CLICK ON THE LEFT MOUSE BUTTON", /* Title Title of the window. */
  56.   NULL,          /* Screen      Connected to the Workbench Screen. */
  57.   NULL,          /* BitMap      No Custom BitMap. */
  58.   100,           /* MinWidth    We will not allow the window to become */
  59.   50,            /* MinHeight   smaller than 100 x 50, and not bigger */
  60.   400,           /* MaxWidth    than 400 x 200. */
  61.   200,           /* MaxHeight */
  62.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  63. };
  64.  
  65.  
  66.  
  67. main()
  68. {
  69.   /* Boolean variable used for the while loop: */
  70.   BOOL close_me;
  71.  
  72.   /* Store some data copied from the IntuitionMessage in these variables: */ 
  73.   ULONG class;           /* IDCMP flag. */
  74.   USHORT code;           /* Code. */
  75.   ULONG seconds, micros; /* Time. */
  76.   
  77.   /* Pointer to an IntuiMessage structure: */
  78.   struct IntuiMessage *my_message;
  79.  
  80.   /* Declare and initialize the time stamps: */
  81.   ULONG sec1 = 0;
  82.   ULONG mic1 = 0;
  83.   ULONG sec2 = 0;
  84.   ULONG mic2 = 0;
  85.  
  86.  
  87.  
  88.   /* Before we can use Intuition we need to open the Intuition Library: */
  89.   IntuitionBase = (struct IntuitionBase *)
  90.     OpenLibrary( "intuition.library", 0 );
  91.   
  92.   if( IntuitionBase == NULL )
  93.     exit(); /* Could NOT open the Intuition Library! */
  94.  
  95.  
  96.  
  97.   /* We will now try to open the window: */
  98.   my_window = (struct Window *) OpenWindow( &my_new_window );
  99.   
  100.   /* Have we opened the window succesfully? */
  101.   if(my_window == NULL)
  102.   {
  103.     /* Could NOT open the Window! */
  104.     
  105.     /* Close the Intuition Library since we have opened it: */
  106.     CloseLibrary( IntuitionBase );
  107.  
  108.     exit();  
  109.   }
  110.  
  111.  
  112.  
  113.   /* We have opened the window, and everything seems to be OK. */
  114.  
  115.  
  116.  
  117.   close_me = FALSE;
  118.  
  119.   /* Stay in the while loop until the user has selected the Close window */
  120.   /* gadget: */
  121.   while( close_me == FALSE )
  122.   {
  123.     /* Wait until we have recieved a message: */
  124.     Wait( 1 << my_window->UserPort->mp_SigBit );
  125.  
  126.     /* As long as we can collect messages successfully we stay in the */
  127.     /* while-loop: */
  128.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  129.     {
  130.       /* After we have successfully collected the message we can read */
  131.       /* it, and save any important values which we maybe want to check */
  132.       /* later: */
  133.       class   = my_message->Class;
  134.       code    = my_message->Code;
  135.       seconds = my_message->Seconds;
  136.       micros  = my_message->Micros;
  137.  
  138.  
  139.       /* After we have read it we reply as fast as possible: */
  140.       /* REMEMBER! Do never try to read a message after you have replied! */
  141.       /* (Some other process has maybe changed it.) */
  142.       ReplyMsg( my_message );
  143.  
  144.  
  145.       /* Check which IDCMP flag was sent: */
  146.       switch( class )
  147.       {
  148.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  149.                close_me=TRUE;
  150.                break;
  151.         
  152.         case MOUSEBUTTONS: /* The user pressed/released a mouse button. */
  153.                if( code == SELECTDOWN )
  154.                {
  155.                  /* Left button pressed. */
  156.                  
  157.                  /* Save the old time: */
  158.                  sec2 = sec1;
  159.                  mic2 = mic1;
  160.     
  161.                  /* Get the new time: */
  162.                  sec1 = seconds;
  163.                  mic1 = micros;
  164.     
  165.                  /* Check if it was a double-click or not: */
  166.                  if( DoubleClick( sec2, mic2, sec1, mic1 ) )
  167.                  {
  168.                    printf("Double-Click!\n");
  169.                    /* Reset the values: */
  170.                    sec1 = 0;
  171.                    mic1 = 0;
  172.                  }
  173.                }
  174.                break;
  175.       }
  176.     }
  177.   }
  178.  
  179.  
  180.  
  181.   /* Close the window: */
  182.   CloseWindow( my_window );
  183.  
  184.  
  185.  
  186.   /* Close the Intuition Library: */
  187.   CloseLibrary( IntuitionBase );
  188. }